package set集合;

import java.util.Objects;

public class apple implements Comparable<apple> {
    private String name;
    private double price;
    private String color;
    private int weight;
    @Override
    public int compareTo(apple o) {
        //return this.weight-o.weight;//返回值0的话会去重重量相等的对象
        return this.weight-o.weight>=0?1:-1;
    }
    public apple() {
    }

    public apple(String name, double price, String color, int weight) {
        this.name = name;
        this.price = price;
        this.color = color;
        this.weight = weight;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public int getWeight() {
        return weight;
    }

    public void setWeight(int weight) {
        this.weight = weight;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        apple apple = (apple) o;
        return Double.compare(apple.price, price) == 0 && weight == apple.weight && Objects.equals(name, apple.name) && Objects.equals(color, apple.color);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, price, color, weight);
    }

    @Override
    public String toString() {
        return "apple{" +
                "name='" + name + '\'' +
                ", price=" + price +
                ", color='" + color + '\'' +
                ", weight=" + weight +
                '}';
    }


}
